Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connects to Server, Reads Messages #10

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

RyannosaurusRex
Copy link
Member

This adds an example .env file, that when properly configured, will pull the name of the server for the configured SERVER_ID. Also adds a test for the new config variable.

@RyannosaurusRex
Copy link
Member Author

This is an attempt at #8, where we can connect and get meaningful data. I can see the username of messages that are entered in the chat, but not the message contents themselves. Might be a permission thing?

@RyannosaurusRex RyannosaurusRex marked this pull request as draft November 29, 2023 03:24
@RyannosaurusRex RyannosaurusRex self-assigned this Nov 29, 2023
@RyannosaurusRex RyannosaurusRex added this to the V1 milestone Nov 29, 2023
@RyannosaurusRex RyannosaurusRex changed the title Enables Environment Variables and Successfully Connects to a Server Connects to Server, Reads Messages Nov 29, 2023
loop {
match connection.recv_event() {
Ok(Event::MessageCreate(message)) => {
println!("{} says: {}", message.author.name, message.content);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we bring in a logging library here?

I'd prefer a structured logging approach that we can hook into various tracing/aggregation tools

match connection.recv_event() {
Ok(Event::MessageCreate(message)) => {
println!("{} says: {}", message.author.name, message.content);
if message.content == "!test" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np: I'd prefer a constant for these values

// At the top of file
static TEST_CMD: &str = "!test";

Comment on lines +81 to +84
fn get_server_id(config: Config) -> u64 {
let num = u64::from_str(config.server_id.as_str()).unwrap();
return num;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is pretty small, maybe just do this in main until we have more config values to extract?

fn main() {
let cfg = Config::from_env_and_args();
let discord = get_discord(cfg.bot_token.as_str());
let server_id = ServerId(self::get_server_id(cfg));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you add the function so that you could wrap the return with ServerId?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants